using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using SFS.SampleApp.Web.Mvc.Resources;
using System.Runtime.Serialization;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Extensions;
using BO = SFS.SampleApp.BusinessObjects;
using System.Web.Mvc;
using SFSdotNet.Framework.Web.Mvc.Validation;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Resources;
using SFSdotNet.Framework.Entities.Metadata;


namespace SFS.SampleApp.Web.Mvc.Models.CustomerAddresses 
{
	public partial class CustomerAddressModel: ModelBase{
		public CustomerAddressModel()
        {
		}
		public override string Id
        {
            get
            {
                return this.CustomerID.ToString();
            }
        }
			
			
        public override string ToString()
        {
		
            return this.AddressType.ToString();
		
        }    
			
	
		[SystemProperty()]		
		public Int32? CustomerID{ get; set; }
		
	
		[SystemProperty()]		
		public Int32? AddressID{ get; set; }
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_ADDRESSTYPE_REQUIRED", ErrorMessageResourceType=typeof(CustomerAddressResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("ADDRESSTYPE", NameResourceType=typeof(CustomerAddressResources))]
	public String   AddressType { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[SystemProperty()]
	[LocalizedDisplayName("ROWGUID", NameResourceType=typeof(CustomerAddressResources))]
	public Guid   rowguid { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_MODIFIEDDATE_REQUIRED", ErrorMessageResourceType=typeof(CustomerAddressResources))]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("MODIFIEDDATE", NameResourceType=typeof(CustomerAddressResources))]
	public DateTime   ModifiedDate { get; set; }
	public string ModifiedDateText {
        get {
            if (ModifiedDate != null)
			
                return ((DateTime)ModifiedDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.ModifiedDate = Convert.ToDateTime(value);
    }
		}
		
		
	
[Exportable()]
		
	[RelationFilterable(DataClassProvider = typeof(Controllers.AddressesController), GetByKeyMethod="GetByKey", GetAllMethod = "GetAll", DataPropertyText = "AddressLine1", DataPropertyValue = "AddressID", FiltrablePropertyPathName="Address.AddressID")]	

	[LocalizedDisplayName("ADDRESS", NameResourceType=typeof(CustomerAddressResources))]
	public Int32  ? FkAddress { get; set; }
		[LocalizedDisplayName("ADDRESS", NameResourceType=typeof(CustomerAddressResources))]
	[Exportable()]
	public string  FkAddressText { get; set; }
    public string FKAddressSafeKey { get; set; }

	
		
	
[Exportable()]
		
	[RelationFilterable(DataClassProvider = typeof(Controllers.CustomersController), GetByKeyMethod="GetByKey", GetAllMethod = "GetAll", DataPropertyText = "Title", DataPropertyValue = "CustomerID", FiltrablePropertyPathName="Customer.CustomerID")]	

	[LocalizedDisplayName("CUSTOMER", NameResourceType=typeof(CustomerAddressResources))]
	public Int32  ? FkCustomer { get; set; }
		[LocalizedDisplayName("CUSTOMER", NameResourceType=typeof(CustomerAddressResources))]
	[Exportable()]
	public string  FkCustomerText { get; set; }
    public string FKCustomerSafeKey { get; set; }

	
		
		
	public override string SafeKey
   	{
		get
        {
			if(this.CustomerID != null && this.AddressID != null)
				return SFSdotNet.Framework.Entities.Utils.GetKey(this ,"CustomerID", "AddressID").Replace("/","-");
			else
				return String.Empty;
		}
    }		
		public void Bind(CustomerAddressModel model){
            
		this.CustomerID = model.CustomerID;
		this.AddressID = model.AddressID;
		this.AddressType = model.AddressType;
		this.rowguid = model.rowguid;
		this.ModifiedDate = model.ModifiedDate;
        }

        public BusinessObjects.CustomerAddress GetBusinessObject()
        {
            BusinessObjects.CustomerAddress result = new BusinessObjects.CustomerAddress();
	if (this.CustomerID != null )
				result.CustomerID = (Int32)this.CustomerID;
				
	if (this.AddressID != null )
				result.AddressID = (Int32)this.AddressID;
				
	if (this.AddressType != null )
				result.AddressType = (String)this.AddressType.Trim().Replace("\t", String.Empty);
				
	if (this.rowguid != null )
				result.rowguid = (Guid)this.rowguid;
				
				result.ModifiedDate = (DateTime)this.ModifiedDate;		
				
	result.Address = new BusinessObjects.Address() { AddressID= (Int32)this.FkAddress };
				
	result.Customer = new BusinessObjects.Customer() { CustomerID= (Int32)this.FkCustomer };
				



            return result;
        }
        public void Bind(BusinessObjects.CustomerAddress businessObject)
        {
            
			this.CustomerID = businessObject.CustomerID;
				
			this.AddressID = businessObject.AddressID;
				
			this.AddressType = businessObject.AddressType != null ? businessObject.AddressType.Trim().Replace("\t", String.Empty) : "";
				
			this.rowguid = businessObject.rowguid;
				
				this.ModifiedDate = (DateTime)businessObject.ModifiedDate;
	        if (businessObject.Address != null){
	                	this.FkAddressText = businessObject.Address.AddressLine1.Trim().Replace("\t", String.Empty); 
										
										
				this.FkAddress = businessObject.Address.AddressID;
                this.FKAddressSafeKey  = SFSdotNet.Framework.Entities.Utils.GetKey(businessObject.Address,"AddressID").Replace("/","-");

			}
	        if (businessObject.Customer != null){
	                	this.FkCustomerText = businessObject.Customer.Title != null ? businessObject.Customer.Title.ToString() : "";; 
										
				this.FkCustomer = businessObject.Customer.CustomerID;
                this.FKCustomerSafeKey  = SFSdotNet.Framework.Entities.Utils.GetKey(businessObject.Customer,"CustomerID").Replace("/","-");

			}
           
        }
	}
}
